<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="box"></div>
</body>
<script>
    var box = document.getElementById("box");
    var timer1 = null;

    a();

    function a() {
        var nowDate = new Date(); // 当前时间
        // var willTime = new Date("2019-10-1 8:00:00");
        var willTime = new Date(2019, 5, 1, 0, 0, 0);
        var willTime = new Date(2019, 4, 13, 14, 06, 10);
        // console.log(willTime);

        var time = willTime - nowDate;
        console.log(timer1);
        if (time <= 0) {
            clearInterval(timer1);
            box.innerHTML = "抢购开始！";
            return false;
        }
        // console.log(time);

        var day = parseInt(time / (24 * 60 * 60 * 1000));
        var hour = parseInt(time / (60 * 60 * 1000)) % 24;
        var minute = parseInt(time / (60 * 1000)) % 60;
        var second = parseInt(time / 1000) % 60;
        var millisecond = time % 1000;

        var str = "距离6-1儿童节还有" + day + "天" + hour + "小时" + minute + "分" + second + "秒<br>";
        box.innerHTML = str;
    }
    // document.write(str);


    // 计时器   每隔 一段时间 执行  特定的代码    
    // setInterval(fn,time)   fn 回调函数     time  间隔时间（单位  ms）
    // 返回值  当前计时器的编号

    // clearInterval(timer)   timer 需要清除的计时器的编号
    timer1 = setInterval(a, 1000);
    // console.log(timer1);

    // var timer2 = setInterval(function () {
    //     console.log("------")
    // }, 1000);
    // console.log(timer2);

    // var timer3 = setInterval(function () {
    //     console.log("++++++")
    // }, 1000);
    // console.log(timer3);



</script>

</html>